#include "initSever.h"

int get_conf(char *ip, char *port, int *threadNum) {
    FILE *pf = fopen("../conf/server.conf", "r");
    fscanf(pf, "%s", ip);
    fscanf(pf, "%s", port);
    fscanf(pf, "%d", threadNum);
    fclose(pf);
    return 0;
}

int init_tcp(const char *ip, const char *port, int *sockfd) {
    *sockfd = socket(AF_INET, SOCK_STREAM, 0);
    int reuse = 1;
    setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(ip);
    addr.sin_port = htons(atoi(port));
    int ret = bind(*sockfd, (struct sockaddr *)&addr, sizeof(addr));
    ERROR_CHECK(ret,-1, "bind");
    listen(*sockfd, 10);
    return 0;
}

